Large buffer and diff limitations

Hello,

I'm trying to diff large buffers using the diff function is the a better why of approaching this do to the limitation of the diff function. I was wondering how I could write so the "\n" would displays correctly rather than using "\\par "?
 

int LinesCntOfBuffer1 = 0
int LinesCntOfBuffer2 = 0
Skip LinesOfBuffer1 = create ()
Skip LinesOfBuffer2 = create ()
Buffer firstrun  = create (0); firstrun  = "Some large Buffer1\nSome large Buffer2\nExtra Line\n"
Buffer secondrun = create (0); secondrun = "Some large Buffer3\nSome large Buffer4\n"
 
void parseBufferLine(Buffer &source, Skip &SkpList, int &lineCnt) {
    Regexp line = regexp2 ".*" // matches up to newline
        int from = 0
        lineCnt = 0 // Zero out
        string match = null
        setempty(SkpList)
        
        while (search(line, source, from)) {
                // takes a line at a time from source
                int offset = end 0
                // end of the match within source
                match = plainText source[from:from+offset]
                // move 'from' over any newline
                
                if (null match) { break } // we are done
                put(SkpList, lineCnt++, match)
                from += offset + 2
                match = null
        }
        
        delete line
        delete source
}
 
void diffx(Skip &Buffer1, Skip &Buffer2)
{
        Buffer buff1 = create(); setempty(buff1)
        Buffer buff2 = create(); setempty(buff2)
        Buffer resBuf = create(); setempty(resBuf)
        Buffer tempBuffer = create(); setempty(tempBuffer)
        string str = null
        string temp = null
        
        //Make buffers have the same line count.
        int newlines = 0
        int i = 0
        if(LinesCntOfBuffer1 < LinesCntOfBuffer2) {
                newlines = LinesCntOfBuffer2 - LinesCntOfBuffer1
                for(i = LinesCntOfBuffer2; i < (LinesCntOfBuffer2+newlines); i++) {
                        put(Buffer1, LinesCntOfBuffer1++, "")
                }
        } else if(LinesCntOfBuffer1 > LinesCntOfBuffer2) {
                newlines = LinesCntOfBuffer1 - LinesCntOfBuffer2
                for(i = LinesCntOfBuffer1; i < (LinesCntOfBuffer1+newlines); i++) {
                        put(Buffer2, LinesCntOfBuffer2++, "")
                }
        } else {
        }
        
        for str in Buffer1 do 
        { 
                setempty(buff1); setempty(buff2)
                int index = key(Buffer1)
                if(find(Buffer2, index, temp))
                {
                        buff1 = str; buff2 = temp
                        diff(resBuf, buff1, buff2, true)
                        combine(tempBuffer, resBuf, 0)
                        buff2 = "\\par "
                        combine(tempBuffer, resBuf, 0)                  
                        /*output
                        buff2 = "\\par " 
                        combine(tempBuffer, resBuf, 0)
                        buff2 = "\\par " 
                        ----------------------------------------------------------------
                        Some large Buffer1Buffer3

                        Some large Buffer2Buffer4

                        Extra Line
                        */
                        combine(tempBuffer, buff2, 0)
                        /*output
                        buff2 = "\n"
                        combine(tempBuffer, buff2, 0) 
                        ----------------------------------------------------------------
                        Some large Buffer1Buffer3Some large Buffer2Buffer4Extra Line
                        */
                }
        }
        
        DB diffDB = create("diff...", styleCentered)
        DBE difftextbox = richText(diffDB, "modifications", "", 850, 400, true)
 
        realize diffDB 
 
        useRTFColour(difftextbox, true) 
        set(difftextbox, tempStringOf tempBuffer) 
 
        show diffDB
        
        delete resBuf 
        delete buff1
        delete buff2
        delete Buffer1
        delete Buffer2
        delete tempBuffer
}
 
parseBufferLine(firstrun, LinesOfBuffer1, LinesCntOfBuffer1)
parseBufferLine(secondrun, LinesOfBuffer2, LinesCntOfBuffer2)
diffx(LinesOfBuffer1, LinesOfBuffer2)
 
delete LinesOfBuffer1
delete LinesOfBuffer2
delete firstrun
delete secondrun

 


-Jim

 


SystemAdmin - Sat Mar 16 00:45:24 EDT 2013

Re: Large buffer and diff limitations
SystemAdmin - Sat Mar 16 11:04:48 EDT 2013

Sorry but I'm a German and in this case I really do not understand the question. May be some others have the same problem.

Re: Large buffer and diff limitations
llandale - Sat Mar 16 14:44:01 EDT 2013

First off Delete line 22:
  • if (null match) { break } // we are done
If you send a string with two "\n" in a row it will abort prematurely.

I'm guessing your "while search" line inadequately handles the case when the input line ends in a EOL. Test this string:
  • Line1\nLine2\n\nLine4\n\n"
which should parse into 6 lines; 3rd and 5th and 6th are empty.

Print the values of "from" and "length(line)" after your loop, then you will know to add somthing like this:
  • int NumExtraLines = length(line) - from // ??as is, or with "+1", or "-1"?? <- Landale brain-dead zone
  • for (i=0; i<NumExtraLines; i++){(put(SkpList, lineCnt++, "")}

***********************************************
Now onto your problem that does not translate into German...

I'm somewhat fuzzy on richText and have adopted a random-modifications approach to debugging; stopping when it looks right. One of those random-modifications that I preserved was to replace all occurances of:
  • "\\par\n"
with
  • "\\par"
But I think it should be replaces with:
  • "\\par ".

My hackles suggest "\\par" is inadequate since I think..
changing:
  • "\\par\nThis Is Text"; which prints two new lines then "This is Text"
to
  • "\\parThis Is Text"; which I think prints no new lines and "Is Text".
since the "\parThis " is not a valid code.

So there you are, something to play with. If you figure out something concrete please let us know.

-Louie

I think perhaps few of my posts transtate into any other language. lol

My "random-approach" has resulted in what is by far my worst code; got rich-text processing spread over 4 include files and most of it poorly commented and also most commented out. I cannot follow it.

On worse news, I think there is a difference is preparation of rich text strings between [1] sending to an attr value, [2] sending to a dialog box, and [3] sending to MS-Word; although [1] and [2] may be the same.

Re: Large buffer and diff limitations
llandale - Sat Mar 16 15:06:09 EDT 2013

As for your algorithm ... It seems to only have potential when the lines are supposed to line up. In huge text were you insert a line early in one; you will produce full mist-matches for the rest of the file. I really don't know how to do it; but I suppose if we could peak at how MS-Word does it we MAY find an algorithm that will allow us to make reasonable break points, and "diff" the parts between these points.

-Louie

Re: Large buffer and diff limitations
SystemAdmin - Mon Mar 18 10:48:05 EDT 2013

llandale - Sat Mar 16 15:06:09 EDT 2013
As for your algorithm ... It seems to only have potential when the lines are supposed to line up. In huge text were you insert a line early in one; you will produce full mist-matches for the rest of the file. I really don't know how to do it; but I suppose if we could peak at how MS-Word does it we MAY find an algorithm that will allow us to make reasonable break points, and "diff" the parts between these points.

-Louie

Hello,

I modified the code but for some reason I need to print the newline character along with an extra space for it to print somewhat correct. Meaning if you remove it everything prints correctly except for the last link within the first printed object. Any help would be appreciated. Thank you.

skp += "\n "// Not sure why I need to print the extra space after the '\n'

 

 

string diffObject(Object& osrc, Skip& Line)
{
    Link l            = null
    ModName_ otherMod = null
    Object othero     = null
    string temp       = null
        int absno         = osrc."Absolute Number"
        Buffer skp        = create (); skp = ""
        
        for l in all(osrc->"*") do {
                ModuleVersion otherVersion = targetVersion l
                otherMod = module(otherVersion)
                                
                if (null otherMod || isDeleted otherMod) {delete otherVersion; continue}
                othero = target l
                if (null othero) {load(otherVersion,false)}
                othero = target l
                if (null othero) {delete otherVersion; continue}
                if (isDeleted othero) {delete otherVersion; continue}              
                if(isDeleted osrc) { 
                        skp += "Softdeleted - "
                }  
                skp += fullName(module(osrc)) "-" probeAttr_(osrc,"Absolute Number") "\t->\t[" fullName(module(l)) "]\t->\t" fullName(otherMod) "-" probeAttr_(othero,"Absolute Number") 
                //skp += fullName(module(osrc)) "-" probeAttr_(osrc,"Absolute Number") "\t->\t" fullName(otherMod) "-" probeAttr_(othero,"Absolute Number") 
                if (isBaseline(otherVersion)) {
                        skp += " [" versionString(otherVersion) "]"
                }
                skp += "\n "// Not sure why I need to print the extra space after the '\n'
                                
                delete otherVersion
        }
        
        temp = stringOf(skp)
        if(!null temp) {
                put(Line, absno, temp)
        }
        
        delete skp
        return temp
}



-Jim



 

 


Attachments

attachment_14958046_transferLinks.dxl

Re: Large buffer and diff limitations
llandale - Mon Mar 18 11:25:34 EDT 2013

SystemAdmin - Mon Mar 18 10:48:05 EDT 2013

Hello,

I modified the code but for some reason I need to print the newline character along with an extra space for it to print somewhat correct. Meaning if you remove it everything prints correctly except for the last link within the first printed object. Any help would be appreciated. Thank you.

skp += "\n "// Not sure why I need to print the extra space after the '\n'

 

 

string diffObject(Object& osrc, Skip& Line)
{
    Link l            = null
    ModName_ otherMod = null
    Object othero     = null
    string temp       = null
        int absno         = osrc."Absolute Number"
        Buffer skp        = create (); skp = ""
        
        for l in all(osrc->"*") do {
                ModuleVersion otherVersion = targetVersion l
                otherMod = module(otherVersion)
                                
                if (null otherMod || isDeleted otherMod) {delete otherVersion; continue}
                othero = target l
                if (null othero) {load(otherVersion,false)}
                othero = target l
                if (null othero) {delete otherVersion; continue}
                if (isDeleted othero) {delete otherVersion; continue}              
                if(isDeleted osrc) { 
                        skp += "Softdeleted - "
                }  
                skp += fullName(module(osrc)) "-" probeAttr_(osrc,"Absolute Number") "\t->\t[" fullName(module(l)) "]\t->\t" fullName(otherMod) "-" probeAttr_(othero,"Absolute Number") 
                //skp += fullName(module(osrc)) "-" probeAttr_(osrc,"Absolute Number") "\t->\t" fullName(otherMod) "-" probeAttr_(othero,"Absolute Number") 
                if (isBaseline(otherVersion)) {
                        skp += " [" versionString(otherVersion) "]"
                }
                skp += "\n "// Not sure why I need to print the extra space after the '\n'
                                
                delete otherVersion
        }
        
        temp = stringOf(skp)
        if(!null temp) {
                put(Line, absno, temp)
        }
        
        delete skp
        return temp
}



-Jim



 

 

I'm guessing the "diff" function doesn't like the '\n' EOL character. I know that I replaced all of them to a strange holding pattern, did the diff, then changed the holding pattern back to "{\par}". Like I said, monkey style random changes until it worked, then I stopped. Seems to me I did the same for the tab '\t' character. Perhaps the "diff" sees the space (not the EOL) as an "End-Of-Word", important when displaying differences.

-Louie

It really ERKS me seeing variable "skp" represent a Buffer!

Re: Large buffer and diff limitations
SystemAdmin - Mon Mar 18 13:15:03 EDT 2013

Found my issue it was the compare against the temp string. see the below code for my fixed logic. Thank you.

void diffObject(Object& osrc, Skip& Line)
{
    Link l            = null
    ModName_ otherMod = null
    Object othero     = null
    int absno         = osrc."Absolute Number"
        Buffer buffLine   = create (); setempty(buffLine)
        
        for l in all(osrc->"*") do {
                ModuleVersion otherVersion = targetVersion l
                otherMod = module(otherVersion)
                                
                if (null otherMod || isDeleted otherMod) {delete otherVersion; continue}
                othero = target l
                if (null othero) {load(otherVersion,false)}
                othero = target l
                if (null othero) {delete otherVersion; continue}
                if (isDeleted othero) {delete otherVersion; continue}              
                if(isDeleted osrc) { 
                        buffLine += "Softdeleted - "
                }  
                buffLine += fullName(module(osrc)) "-" probeAttr_(osrc,"Absolute Number") "\t->\t[" fullName(module(l)) "]\t->\t" fullName(otherMod) "-" probeAttr_(othero,"Absolute Number") 
                //buffLine += fullName(module(osrc)) "-" probeAttr_(osrc,"Absolute Number") "\t->\t" fullName(otherMod) "-" probeAttr_(othero,"Absolute Number") 
                if (isBaseline(otherVersion)) {
                        buffLine += " [" versionString(otherVersion) "]"
                }
                buffLine += "\n"
                                
                delete otherVersion
        }
        
        if(!null buffLine) {
                put(Line, absno, stringOf buffLine)
        }
        
        delete buffLine
}

 


-Jim